package com.code.family.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 自定义配置类, 用于读取application.yaml配置文件中的自定义配置项
 * @author 上玄
 * @since 2024-12-23
 */
@Data
@Component
@ConfigurationProperties(prefix = "custom")
public class CustomConfig {
    // 域名、端口、上传路径
    private String domain;
    private String port;
    private String uploadPath;

    // 开发环境构建完整的文件URL
    public String getFullUploadPath() {
        if (domain == null || port == null || uploadPath == null) {
            return null;
        }
        // 开发环境构建完整的文件URL
        if (domain.startsWith("http://")) {
            return domain + ":" + port + uploadPath;
        }
        // 生产环境构建完整的文件URL
        if (domain.startsWith("https://")) {
            return domain + uploadPath;
        }
        return domain + ":" + port + uploadPath;
    }
}
